<!-- 新增、编辑 -->

<template>
    <el-dialog :model-value="dialogFormVisible" :destroy-on-close="true" :title="dialogTitle" width="450px"
        @close="emits('closeDialog')">
        <el-form ref="dialogFormRef" :model="dialogForm" :label-width="formLabelWidth" :rules="rules">
            <el-form-item label="是否可用" :label-width="formLabelWidth" prop="is_active">
                <el-select v-model="dialogForm.is_active" placeholder="是否可用">
                    <el-option label="否" :value="0" />
                    <el-option label="是" :value="1" />
                </el-select>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="emits('cancel')">取消</el-button>
                <el-button type="primary" @click="submit(dialogForm)" :loading="btnLoading">提交</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
    dialogFormVisible: {
        type: Boolean,
        default: false
    },
    dialogForm: {
        type: Object,
        default: {
            id: "",
            is_active: "",
        }
    },
    btnLoading: {
        type: Boolean,
        default: false
    },
    dialogTitle: {
        type: String,
        default: ""
    }
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);
const formLabelWidth = "140px";
// 校验
const rules = {
};
// 提交
const submit = dialogForm => {
    dialogFormRef.value
        .validate()
        .then(async () => {
            try {
                emits("submitForm", {id: dialogForm.id, is_active: dialogForm.is_active});
            } catch (error) {
                return false;
            }
        })
        .catch(error => {
            return false;
        });
};
</script>
  